/**
 * 按钮点击
 */
(function ($) {
    "use strict";

    let $dom = {
        "changeBase": $("#change-base"),
        "changeLogin": $("#change-login"),
        "changeConnect": $("#change-connect"),
        "changeAvatar": $("#change-avatar")
    };

    /**
     * 修改基础信息
     */
    $dom.changeBase.on("click",function () {
        window.top.changeIframe("/student/frame/changeBaseInfo");
    });

    /**
     * 修改登录信息
     */
    $dom.changeLogin.on("click",function () {
        window.top.changeIframe("/student/frame/changeLoginInfo");
    });

    /**
     * 修改联系信息
     */
    $dom.changeConnect.on("click",function () {
        window.top.changeIframe("/student/frame/changeConnect");
    });

    /**
     * 修改头像
     */
    $dom.changeAvatar.on("click",function () {
        window.top.changeIframe("/student/frame/student-alter-avatar");
    });
})(window.jQuery);

/**
 * 查找年级信息
 */
(function ($) {
    "use strict";

    let grade = $("#grade");

    /**
     * 查找年级信息
     */
    function queryGrade(id) {
        $.ajax({
            url: "/query/subjectById",
            type: "post",
            dataType: "json",
            data: {"id": id},
            success: function (result) {
                if( (typeof result) === "object" ){
                    let status = result.status;
                    if(status === 200){
                        let info = result.info;
                        if( (typeof info) === "string" ){
                            info = JSON.parse(info);
                        }

                        try{
                            let text = "【"+info.gradeSection+"】" + info.grade;
                            grade.text(text);
                        }catch(err){
                            console.error(err);
                        }
                    }
                }
            }
        })
    }

    $(document).ready(function () {
        let id = grade.attr("data-id");

        id = parseInt(id);
        if(id >= 10){
            queryGrade(id);
        }
    });
})(window.jQuery);